//@author A0085897A

import java.util.Calendar;
import java.util.GregorianCalendar;

public class Transaction {

	// ATTRIBUTES
	private int _ID;
	private String _name;
	private double _value;
	private Calendar _date;
	private String _category;
	private String _paymentMethod;
	private String _remarks;
	private TransactionStatus _status;
	private TransactionType _type;

	// CONSTRUCTOR
	public Transaction(String name, double value, String type, String date, String category, String paymentMethod, String remarks, String status) {
		this._ID = -1;
		this._name = name;
		this._value = value;
		this._type = TransactionType.valueOf(type.toUpperCase());
		this._date = Transaction.parseDate(date);
		this._category = category.toUpperCase();
		this._paymentMethod = paymentMethod.toUpperCase();
		this._remarks = remarks;
		this._status = TransactionStatus.valueOf(status.toUpperCase());
	}

	// METHODS
	// Getters
	public int getID() {
		return this._ID;
	}
	public String getName() {
		return this._name;
	}
	public double getValue() {
		return this._value;
	}
	public TransactionType getType() {
		return this._type;
	}
	public TransactionStatus getStatus() {
		return this._status;
	}
	public Calendar getDate() {
		return this._date;
	}
	public String getDateStr() {
		return String.format("%02d", this.getDate().get(Calendar.DAY_OF_MONTH)) + "." + String.format("%02d", this.getDate().get(Calendar.MONTH)+1) + "." + this.getDate().get(Calendar.YEAR);
	}
	public String getCategory() {
		return this._category;
	}
	public String getPaymentMethod() {
		return this._paymentMethod;
	}
	public String getRemarks() {
		return this._remarks;
	}
	
	// Setters
	public void setID(int ID) {
		this._ID = ID;
	}
	public void setName(String name){
		this._name = name;
	}
	public void setValue(double value){
		this._value = value;
	}
	public void setType(String type) {
		this._type = TransactionType.valueOf(type.toUpperCase());	
	}
	public void setDate(String date) {
		this._date = Transaction.parseDate(date);
	}
	public void setCategory(String category){
		this._category = category;
	}
	public void setPaymentMethod(String paymentMethod){
		this._paymentMethod = paymentMethod;
	}
	public void setRemarks(String remarks){
		this._remarks = remarks;
	}
	public void setStatus(String status){
		this._status = TransactionStatus.valueOf(status.toUpperCase());
	}
	// Parse date into a Calendar object
	public static Calendar parseDate(String date) {
		String[] arr = date.split("\\.");
		return new GregorianCalendar(Integer.parseInt(arr[2]), Integer.parseInt(arr[1]) - 1, Integer.parseInt(arr[0]));
	}
	// Return a copy of this Transaction
	@Override
	public Transaction clone() {
		return new Transaction(this.getName(), this.getValue(), this.getType().toString(), this.getDateStr(), this.getCategory(), this.getPaymentMethod(), this.getRemarks(), this.getStatus().toString());
	}

}
